<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>扫码核券</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <script src="${pageContext.request.contextPath}/resources/plugins/h+/js/jquery.min.js?v=2.1.4"></script>
    <link rel="shortcut icon" href="favicon.ico"> <link href="${pageContext.request.contextPath}/resources/plugins/h+/css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/resources/plugins/h+/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/resources/plugins/h+/css/style.min862f.css?v=4.1.0" rel="stylesheet">
    <script src="${pageContext.request.contextPath}/resources/plugins/h+/js/plugins/validate/jquery.validate.min.js"></script>

    <style>
        table.shuxtable tr td{
            padding:5px 0;
        }
    </style>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>扫码核券</h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                    </div>
                </div>
                <div class="ibox-content" style="height:450px">

                        <div class="form-group">
                            <label class="col-sm-2 control-label" style="text-align: right">码值:</label>
                            <div class="col-sm-6">
                                <input id="txt_voucher" name="" class="form-control" type="text">
                                <span class="help-block m-b-none"><i class="fa fa-info-circle"></i></span>
                            </div>
                            <div class="col-sm-2">
                                <a href="toQueryVoucher.ac" target="_self">核券列表</a>
                            </div>
                        </div>
                    <table class="shuxtable" id="goodsInfo" style="width:500px;margin:0 auto; display: none">
                        <tr><td colspan="2" style="text-align:center;"><p style="color: red;text-align:center;">商品信息</p></td></tr>
                        <tr ><td>图片:</td><td id="pic"></td></tr>
                        <tr><td>名称:</td><td id="proname"></td></tr>
                        <tr id="tr_firstValue"><td>一级属性:</td><td id="firstValue"></td></tr>
                        <tr id="tr_secondValue"><td>二级属性:</td><td id="secondValue"></td></tr>
                        <tr id="tr_thirdValue"><td>三级属性:</td><td id="thirdValue"></td></tr>
                        <tr><td>上架状态:</td><td id="isSale"></td></tr>
                        <tr><td>价格:</td><td id="price"></td></tr>
                        <tr><td>库存:</td><td id="stock"></td></tr>
                        <tr><td>标签:</td><td id="tags"></td></tr>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>


<script src="${pageContext.request.contextPath}/resources/plugins/h+/js/bootstrap.min.js?v=3.3.6"></script>
<script src="${pageContext.request.contextPath}/resources/plugins/h+/js/content.min.js?v=1.0.0"></script>
<script src="${pageContext.request.contextPath}/resources/plugins/h+/js/demo/form-validate-demo.min.js"></script>
<script src="${pageContext.request.contextPath}/resources/plugins/h+/js/plugins/layer2.4/layer.js"></script>

<script>
    document.onkeydown=function(event){
        var e = event || window.event || arguments.callee.caller.arguments[0];
        if(e && e.keyCode==27){ // 按 Esc
            //要做的事情
        }
        if(e && e.keyCode==113){ // 按 F2
            //要做的事情
        }
        if(e && e.keyCode==13){ // enter 键
            //要做的事情
            getPro();
        }
    };

    function getPro(){
        var url = "orther_getPro.ac";
        var voucher=$("#txt_voucher").val();
        $.ajax({
            type: "post",

            url: url,
            data: {voucher:voucher}, // 你的formid
            dataType: 'json',
            success: function(data) {
                if(data==null){
                    alert("无数据：核劵失败！");
                }else{
                    if(data['resultCode']==4 || data['resultCode']==3){
                        $("#goodsInfo").show();

                        if(data['goodsPath']!=undefined){
                            $("#pic").html('<img width="180" src="'+data['goodsPath']+'" >');
                        }
                        if(data['name']!=undefined){
                            $("#proname").html(data['name']);
                        }
                        if(data['firstValue']!=null && data['firstValue']!=''){
                            $("#firstValue").html(data['firstValue']);
                        }else{
                            $("#tr_firstValue").hide();
                        }
                        if(data['secondValue']!=null && data['secondValue']!=''){
                            $("#secondValue").html(data['secondValue']);
                        }else{
                            $("#tr_secondValue").hide();
                        }
                        if(data['thirdValue']!=null && data['thirdValue']!=''){
                            $("#thirdValue").html(data['thirdValue']);
                        }else{
                            $("#tr_thirdValue").hide();
                        }
                        $("#isSale").html(data['isSale']==1?'<font style="color:green">上架</font>':'<font style="color:red">下架</font>');
                        $("#price").html(data['price']+'元');
                        $("#stock").html(data['stock']+'件');
                        var tags = data['tags'];
                        var tagsHtml="";
                        if(tags!=null && tags.length>0){
                            $.each(tags, function(i) {
                                tagsHtml+=tags[i].tagName+'、';
                            });
                            tagsHtml=tagsHtml.substring(0, tagsHtml.length-1);
                        }
                        $("#tags").html(tagsHtml);
                    }
                    if(data['resultCode']!=4){
                        alert(data['resultMsg']);
                    }else{
                        alert("核劵成功！");
                    }

                }
            },
            error:function(XMLHttpRequest, textStatus, errorThrown){
                alert("错误:核劵失败！");
            }
        });
    }
</script>

</body>

</html>

